#pragma once

#include <windows.h>

#include "dib.h"
#include "window.h"

/** 
 * \ingroup ti6
 *
 * \brief
 * The ImageBox class represents a control used to show an image. The
 * control is added to MainWindow and is responsible for drawing the
 * image on the screen, with the right position and size. The ImageBox
 * control does not accept any input.
 *
 * Copyright (c) Academie voor ICT en Media 2007 - 2008
 */
class ImageBox: public Window
{
public:
	/**
	 \brief
	 Default constructor. Initialize the instance using create().
	 */
	ImageBox();

	/**
	 \brief
	 Destructor.
	 */
	~ImageBox();

	/**
	 \brief
	 Initialize the instance. This will register the window class if
	 neccesary and create the window itself.
	 
	 \param hWndParent Handle to the parent window.
	 \param hInstance Instance handle.
	 \return True is returned if the window is successfully created. In
	   case of an error, false is returned.
	 */
	bool create( HWND hWndParent, HINSTANCE hInstance );
	
	/**
	 \brief
	 Set the position of the image box. Use the other setPosition() overload
	 to set the position for the image in this image box.
	 
	 \param rect The rectangle which identifies the position and size of the window.
	 \param repaint Identifies whether the window should be repainted.
	 \return TRUE is returned if the position is successfully set. In case of
	   an error, FALSE is returned.
	 */
	BOOL setPosition( RECT rect, BOOL repaint = TRUE );

	/**
	 \brief
	 Set the visibility of the window.
	 
	 \param nCmdShow SW_SHOW to show the window, SW_HIDE to make the window
	   invisible.
	 */
	void show( int nCmdShow = SW_SHOW );

	/**
	 \brief
	 Get a pointer to the DIB, which is currently showed.
	 
	 \return A pointer to the DIB.
	 */
	DIB* dib();

	/**
	 \brief
	 Set the DIB which is showed. The image box will be repainted after the
	 call to this function.
	 
	 \param *dib A pointer to the DIB. Set this to NULL to clear the image box.
	 */
	void setDib( DIB *dib );

	/**
	 \brief
	 Get the position of the DIB. The position is measured at the top-left edge
	 of the image.
	 
	 \return The position of the DIB.
	 */
	POINT position() const;

	/**
	 \brief
	 Set the position of the DIB. This is specified at the top-left edge of
	 the image.
	 
	 \param pos The position for the DIB.
	 */
	void setPosition( POINT pos );

	/**
	 \brief
	 Center the image within the image box.
	 */
	void center();

	/**
	 \brief
	 Get the current scale at which the image is showed. When the image is
	 showed in actual size, the scale is equal to 1.0.
	 
	 \return The scale.
	 */
	double scale();

	/**
	 \brief
	 Set the scale at which the image is showed. To show the image in actual
	 size, specify 1.0.
	 
	 \param scale The scale.
	 */
	void setScale( double scale );

	/**
	 \brief
	 Handle messages, specific for this window.
	 
	 \param uMsg The message id.
	 \param wParam 32 bits value, specific to the message.
	 \param lParam 32 bits value, specific to the message.
	 \return The result of the processing, which is dependent on the type of message.
	 */
	virtual LRESULT handleMessage( UINT uMsg, WPARAM wParam, LPARAM lParam );

	/**
	 \brief
	 Get a handle to the window. Do not close this handle.

	 \return A handle to this window.
	 */
	HWND hWnd() const;

private:
	/**
	 \brief
	 Register the window class. This is a 'template' for windows which
	 is registered in the kernel. The window class for image boxes is
	 registered under the name "ImageBox".

	 \param hInstance The instance handle.
	 \return If the window class is successfully registered, true is
	   returned. False is returned in case of an error.
	 */
	static bool registerWndClass( HINSTANCE hInstance );

	/**
	 The image which is currently showed.
	 */
	DIB *_dib;

	/**
	 A handle to the window.
	 */
	HWND _hWnd;

	/**
	 The position of the image.
	 */
	POINT _position;

	/**
	 The scale of the image. 1.0 is actual size (100%).
	 */
	double _scale;

	/**
	 The window class.
	 */
	static ATOM _wndClass;
};
